import 'package:pacsun/components/appbar.dart';
import 'package:pacsun/model/taskModel.dart';
import 'package:pacsun/provider/taskDetailProv.dart';
import 'package:pacsun/view/task/theme/app_colors.dart';
import 'package:pacsun/view/task/widgets/cache_network_image.dart';
import 'package:pacsun/view/task/widgets/task_flow_sheet.dart';
import 'package:pacsun/view/task/widgets/video_player_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import '../create/mediaPicker/mediaPickerPage.dart';
import './widgets/photo_preview_page.dart';
import '../create/publish/publishPage.dart';

class TaskDetailPage extends StatefulWidget {
  final String taskStatus; // 任务状态
  final int taskId;
  final String taskType;
  const TaskDetailPage({
    super.key,
    this.taskStatus = 'default',
    required this.taskId,
    required this.taskType,
  });
  @override
  State<TaskDetailPage> createState() => _TaskDetailPageState();
}

class _TaskDetailPageState extends State<TaskDetailPage> with RouteAware {
  late TaskDetailProv taskDetailViewModel;
  @override
  void initState() {
    taskDetailViewModel = Provider.of<TaskDetailProv>(context, listen: false);
    taskDetailViewModel.setTaskType(widget.taskType);
    if (mounted) {
      taskDetailViewModel.initTaskDetail(widget.taskId.toString());
    }
    super.initState();
  }

  @override
  void dispose() {
    taskDetailViewModel.clearTaskDetail();
    super.dispose();
  }

  void openPreViewImage(
      List<String> imageUrls, String heroTag, int initialIndex) {
    Navigator.push(
      context,
      PageRouteBuilder(
        pageBuilder: (context, animation, secondaryAnimation) =>
            PhotoPreviewPage(
          imageUrls: imageUrls,
          heroTag: heroTag,
          initialIndex: initialIndex,
        ),
        transitionsBuilder: (context, animation, secondaryAnimation, child) {
          return FadeTransition(
            opacity: animation,
            child: child,
          );
        },
        transitionDuration: const Duration(milliseconds: 300),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    // build方法中直接获取Provider数据
    final taskDetailViewModel = Provider.of<TaskDetailProv>(context);
    // 任务信息
    final task = taskDetailViewModel.taskDtail ?? TaskModal.fromJson({}, '');
    // 任务商品信息
    List<ProductModel> productList = taskDetailViewModel.productList ?? [];
    // 任务参考图片
    List<String> referenceImages = taskDetailViewModel.referenceImages ?? [];
    List<FlowItem>? taskFlows = taskDetailViewModel.taskFlows;
    // 审核记录
    List<AuditLog> auditLogList = taskDetailViewModel.auditLogList ?? [];
    // print('object${taskFlows?.map((toElement) => toElement.toJson())}');
    // 任务帖子详情
    ContentBo? contentBo = taskDetailViewModel.contentBo;

    // 示例视频
    List<MediaBoList> referenceVideos =
        taskDetailViewModel.referenceVideos ?? [];

    // 奖励信息
    List<TaskRewardList> taskRewardList = task.taskRewardList;

    // 判断是否可以发布
    bool isJoinNow = taskDetailViewModel.isJoinNow;
    // 判断是否过期
    bool isExpired = taskDetailViewModel.isExpired;

    // 根据状态判断时候显示content retry
    int currenStatus = 0;
    if (taskFlows != null && taskFlows.isNotEmpty) {
      final status = taskFlows[0].status;
      if (status is int) {
        currenStatus = int.parse(status);
      } else if (status is String) {
        currenStatus = int.tryParse(status) ?? 0;
      }
    }
    return MediaQuery(
      data: MediaQuery.of(context).copyWith(textScaler: TextScaler.noScaling),
      child: Scaffold(
        backgroundColor: Colors.black,
        extendBodyBehindAppBar: true,
        appBar: CommonTransparentAppBar(),
        body: Stack(
          children: [
            AppBarBg(),
            SafeArea(
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    // 主图片+右侧内容
                    _buildMainImage(task),
                    // 任务流程
                    if (task.frontEndStatus.UNDER_REVIEW.isNotEmpty)
                      TaskFlow(
                          taskFlows: taskFlows,
                          auditLogList: auditLogList,
                          contentBo: contentBo,
                          isExpired: isExpired),
                    // 奖励信息
                    if (taskRewardList.isNotEmpty) _buildReward(task),

                    // 任务描述
                    _buildSection(
                      titleIconSrc: 'assets/icons/icon_task_desc.svg',
                      title: 'DESCRIPTION',
                      contentSlot: HtmlWidget(
                        task.description.replaceAll('\n', '<br>'),
                        textStyle: TextStyle(
                          fontFamily: 'Poppins',
                          fontWeight: FontWeight.w400,
                          fontSize: 14.sp,
                          color: Color(0xFF949494),
                        ),
                      ),
                    ),
                    // 商品信息
                    if (productList.isNotEmpty) ...[
                      _buildSection(
                        titleIconSrc: 'assets/icons/icon_product.svg',
                        title: 'PRODUCT',
                        padding: EdgeInsets.only(
                                left: 16, top: 12, right: 0, bottom: 0)
                            .r,
                        contentSlot: Padding(
                          padding: EdgeInsets.only(top: 6).r,
                          child: SizedBox(
                            height: 150.h,
                            child: ListView.separated(
                              scrollDirection: Axis.horizontal,
                              itemCount: productList.length,
                              separatorBuilder: (context, index) =>
                                  SizedBox(width: 28.w),
                              itemBuilder: (context, index) {
                                return _buildProductItem(
                                    product: productList[index]);
                              },
                            ),
                          ),
                        ),
                      ),
                    ],

                    // 参考图片信息
                    if (referenceVideos.isNotEmpty ||
                        referenceImages.isNotEmpty) ...[
                      _buildSection(
                        titleIconSrc: 'assets/icons/icon_reference.svg',
                        title: 'REFERENCE',
                        padding: EdgeInsets.only(
                                left: 14, top: 12, right: 0, bottom: 20)
                            .r,
                        contentSlot: Padding(
                          padding: EdgeInsets.only(top: 10).r,
                          child: SizedBox(
                            height: 78.h,
                            child: ListView.separated(
                              scrollDirection: Axis.horizontal,
                              itemCount: referenceVideos.length +
                                  referenceImages.length,
                              separatorBuilder: (context, index) => SizedBox(
                                width: 14.w,
                              ),
                              itemBuilder: (context, index) =>
                                  _buildReferenceItems(
                                      referenceImages, referenceVideos, index),
                            ),
                          ),
                        ),
                      ),
                    ],

                    SizedBox(height: 30.h)
                  ],
                ),
              ),
            ),
          ],
        ),
        bottomNavigationBar: isJoinNow || currenStatus == 3
            ? _buildBottomButton(currenStatus)
            : const SizedBox.shrink(),
      ),
    );
  }

  Widget _buildReferenceItems(List<String> referenceImages,
      List<MediaBoList> referenceVideos, int index) {
    if (index < referenceImages.length && referenceImages.isNotEmpty) {
      return GestureDetector(
        onTap: () => {
          // 打开预览页面
          openPreViewImage(referenceImages, 'image_preview_$index', index)
        },
        child: Hero(
          tag: 'image_preview_$index',
          child: CacheNetworkImage(
            borderRadius: 4.r,
            imageUrl: referenceImages[index],
            width: 78.w,
            height: 78.h,
            fit: BoxFit.cover,
          ),
        ),
      );
    } else {
      return GestureDetector(
        onTap: () => {
          Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => VideoPlayerPage(
                videoUrl: referenceVideos[index - referenceImages.length].url,
              ),
            ),
          )
        },
        child: Container(
          width: 78.w,
          height: 78.h,
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(4).r,
              color: AppColors.white.withAlpha(30),
              image:
                  referenceVideos[index - referenceImages.length].thumbnall !=
                          ''
                      ? DecorationImage(
                          image: NetworkImage(
                              referenceVideos[index - referenceImages.length]
                                  .thumbnall),
                          fit: BoxFit.cover)
                      : null),
          alignment: Alignment.center,
          child: Icon(Icons.play_arrow, color: Colors.white, size: 32.sp),
        ),
      );
    }
  }

  Widget _buildMainImage(TaskModal task) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 20, vertical: 16.h).r,
      child: SizedBox(
        width: double.infinity,
        height: 70.h,
        child: Row(
          children: [
            CacheNetworkImage(
              imageUrl: task.bannerUrl,
              width: 70.w,
              height: 70.h,
              borderRadius: 8.r,
              fit: BoxFit.cover,
            ),
            SizedBox(width: 16.w),
            Expanded(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    task.taskName,
                    style: customTextStyle(
                      fontWeight: 900,
                      fontSize: 18,
                      overflow: TextOverflow.ellipsis,
                      height: 1.1,
                    ),
                    maxLines: 2,
                  ),
                  // _buildTag(task.taskTypeStr),
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      if (task.platformIconUrl != '') ...[
                        CacheNetworkImage(
                          imageUrl: task.platformIconUrl,
                          width: 14.w,
                          height: 14.h,
                          imageType: ImageType.asset,
                          borderRadius: 2,
                        ),
                        SizedBox(width: 6.w),
                        Text(task.platformStr,
                            style: customTextStyle(
                              color: FamilyTextColor.white,
                              fontWeight: 500,
                              opacity: 0.5,
                              height: 1,
                            )),
                        SizedBox(width: 7.w),
                      ],
                      SvgPicture.asset(
                        'assets/icons/icon_date.svg',
                        width: 12.w,
                        height: 12.h,
                      ),
                      SizedBox(width: 3.w),
                      Flexible(
                        child: Text(
                          // "Before: ${task.createTime}",
                          // "Expires on: ${task.endDateStr}",
                          task.endDateStr,
                          style: customTextStyle(
                            color: FamilyTextColor.white,
                            opacity: 0.5,
                            height: 1,
                          ),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      )
                    ],
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget _buildReward(TaskModal task) {
    return Container(
        decoration: BoxDecoration(
          color: Color(0xFF222222),
          borderRadius: BorderRadius.circular(8.r),
        ),
        margin: EdgeInsets.only(left: 20, right: 20, top: 12).r,
        padding: EdgeInsets.only(top: 12, left: 14, right: 14, bottom: 12).r,
        child: Column(
          children: task.taskRewardList.asMap().entries.map((e) {
            return Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                e.key == 0
                    ? const CardTitle(
                        icon: 'assets/icons/icon_money.svg', title: 'REWARDS')
                    : const SizedBox.shrink(),
                Container(
                    margin: EdgeInsets.only(top: e.key != 0 ? 8 : 0).r,
                    child: _buildRewardText(
                        type: e.value.type, text: e.value.value))
              ],
            );
          }).toList(),
        ));
  }

  // 奖励文本
  Widget _buildRewardText({
    required String type,
    required String text,
    CrossAxisAlignment? crossAxisAlignment,
    MainAxisAlignment? mainAxisAlignment,
  }) {
    final Color textColor =
        type == 'points' ? Color(0xFF63B9FF) : Color(0xFFFFC640);
    final TextStyle textStyle = TextStyle(
      fontFamily: 'Poppins',
      fontWeight: FontWeight.w700,
      fontSize: 18.sp,
      color: textColor,
      height: 1,
    );

    final String iconSrc = type == 'points'
        ? 'assets/icons/icon_points.svg'
        : 'assets/icons/icon_money1.svg';

    return Row(
      crossAxisAlignment: crossAxisAlignment ?? CrossAxisAlignment.center,
      mainAxisAlignment: mainAxisAlignment ?? MainAxisAlignment.start,
      children: [
        Text(
          '+$text',
          style: textStyle,
        ),
        SizedBox(
          width: 5.w,
        ),
        SvgPicture.asset(iconSrc, width: 16.w, height: 16.h)
      ],
    );
  }

  Widget _buildTag(String tag) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.h),
      decoration: BoxDecoration(
        color: Color(0xFF3DAC7C),
        borderRadius: BorderRadius.circular(4.r),
      ),
      child: Text(tag, style: customTextStyle(fontSize: 10)),
    );
  }

  Widget _buildSection({
    required String title,
    required String titleIconSrc,
    Widget? contentSlot,
    double? contentMarginTop,
    EdgeInsetsGeometry? padding,
  }) {
    return Container(
      decoration: BoxDecoration(
        color: Color(0xFF222222),
        borderRadius: BorderRadius.circular(8.r),
      ),
      margin: EdgeInsets.only(left: 20, right: 20, top: 12).r,
      padding: padding ??
          EdgeInsets.only(top: 12, left: 14, right: 14, bottom: 12).r,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          CardTitle(
            icon: titleIconSrc,
            title: title,
          ),
          SizedBox(height: contentMarginTop ?? 8.h),
          contentSlot ?? const SizedBox.shrink(),
        ],
      ),
    );
  }

  Widget _buildProductItem({required ProductModel product}) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        GestureDetector(
          onTap: () => {
            // openPreViewImage([product.imageUrl],'image_preview_$index' )
          },
          child: CacheNetworkImage(
            imageUrl: product.imageUrl,
            width: 91.w,
            height: 91.w,
            fit: BoxFit.cover,
            borderRadius: 8.r,
          ),
        ),
        SizedBox(height: 4.h),
        SizedBox(
          width: 88.w,
          child: Text(
            product.name,
            style: customTextStyle(
              fontWeight: 500,
              overflow: TextOverflow.ellipsis,
              height: 1.5,
            ),
            maxLines: 2,
          ),
        ),
        // SizedBox(height: 4.h),
        // Text(
        //   'CN¥ ${product.price}',
        //   style: customTextStyle(color: FamilyTextColor.red),
        // )
      ],
    );
  }

  Widget _buildBottomButton(int currenStatus) {
    // 状态：审核成功/审核中不显示，审核失败显示RETRY，其他显示JOIN NOW
    String btnText = currenStatus == 3 ? 'RETRY' : 'JOIN NOW';
    return Container(
      color: Colors.transparent,
      padding: EdgeInsets.fromLTRB(20.w, 0, 20.w, 24.h),
      width: double.infinity,
      child: SizedBox(
        width: double.infinity,
        height: 56.h,
        child: ElevatedButton(
          onPressed: () => _handleJoinButtonPress(),
          style: ElevatedButton.styleFrom(
            backgroundColor: Color(0xFFD73030),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(27.5.r),
            ),
            elevation: 0,
            shadowColor: Colors.transparent,
            splashFactory: NoSplash.splashFactory,
          ),
          child: Text(
            btnText,
            style: TextStyle(
              fontFamily: 'Poppins',
              fontWeight: FontWeight.w900,
              fontSize: 20.sp,
              color: Colors.white,
            ),
          ),
        ),
      ),
    );
  }

  void _handleJoinButtonPress() {
    final task = taskDetailViewModel.taskDtail ?? TaskModal.fromJson({}, '');

    print('=== 任务参数检查 ===');
    print('task.taskconfigid: ${task.taskconfigid}');
    print('task.taskrecordid: ${task.taskrecordid}');
    print('task.taskType: ${task.taskType}');
    print('==================');

    // 检查是否为种草任务 "CONTENT_TASK" (对应数字 2)
    if (task.taskType == 'CONTENT_TASK' || task.taskType == 'PRODUCT_TASK') {
      // 如果有taskRecordId，直接跳转到发布页面
      if (task.taskrecordid != null && task.taskrecordid != 0) {
        print('=== 有taskRecordId，直接跳转到发布页面 ===');
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => PublishPage(
              taskConfigId: task.taskconfigid,
              taskRecordId: task.taskrecordid,
              loadDraftOnInit: true, // 新增参数，表示需要加载草稿
            ),
          ),
        );
      } else {
        print('=== 没有taskRecordId，跳转到媒体选择页面 ===');
        // 跳转到媒体选择页面，传递正确的参数
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => MediaPickerPage(
              taskConfigId: task.taskconfigid,
              taskRecordId: task.taskrecordid,
            ),
          ),
        );
      }
    } else {
      // 其他类型的任务处理
      print('此任务类型不需要上传媒体内容');
    }
  }
}

class CardTitle extends StatelessWidget {
  final String icon;
  final String title;
  const CardTitle({super.key, required this.icon, required this.title});

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        SvgPicture.asset(
          icon,
          width: 20.w,
          height: 20.h,
        ),
        SizedBox(
          width: 8.w,
        ),
        Text(title, style: customTextStyle(fontSize: 16, fontWeight: 600)),
      ],
    );
  }
}

// 审核流程
class TaskFlow extends StatelessWidget {
  final List<FlowItem>? taskFlows;
  final List<AuditLog>? auditLogList;
  final ContentBo? contentBo;
  final bool isExpired;
  const TaskFlow({
    super.key,
    this.taskFlows,
    this.auditLogList,
    this.contentBo,
    required this.isExpired,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Color(0xFF222222),
        borderRadius: BorderRadius.circular(8.r),
      ),
      margin: EdgeInsets.only(left: 20, right: 20, top: 12).r,
      padding: EdgeInsets.only(top: 12, left: 14, right: 14, bottom: 12).r,
      child: Opacity(
        opacity: isExpired ? 0.5 : 1,
        child: Stack(
          clipBehavior: Clip.none,
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    CacheNetworkImage(
                      imageUrl: contentBo?.thumbnail ?? '',
                      width: 40.w,
                      height: 40.h,
                      borderRadius: 4.r,
                    ),
                    SizedBox(width: 8.w),
                    Expanded(
                      child: Text(
                        contentBo?.title ?? '',
                        maxLines: 2,
                        style: customTextStyle(
                          fontSize: 14,
                          height: 1.3,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                    )
                  ],
                ),
                SizedBox(height: 8.h),
                ...taskFlows!.map((e) {
                  return TaskFlowStep(
                      step: e.step,
                      stateIcon: e.icon,
                      stepTitle: e.title,
                      isActive: e.active || e.retry,
                      status: e.status,
                      retry: e.retry,
                      statusStr: e.statusStr,
                      isExpired: isExpired);
                }),
              ],
            ),
            if (isExpired)
              Positioned(
                right: -14.w,
                bottom: -12.h,
                child: SvgPicture.asset(
                  'assets/icons/icon_task_detail_expried.svg',
                  width: 109.w,
                  height: 101.h,
                  color: Color(0XFFD9D9D9),
                ),
              )
          ],
        ),
      ),
    );
  }
}

class TaskFlowStep extends StatelessWidget {
  final int step;
  final String status;
  final String stepTitle;
  final String stateIcon;
  final String statusStr;
  final bool isActive;
  final bool retry;
  final bool isExpired;

  const TaskFlowStep({
    super.key,
    required this.step,
    required this.status,
    required this.stateIcon,
    required this.statusStr,
    required this.stepTitle,
    required this.isActive,
    required this.retry,
    required this.isExpired,
  });

  @override
  Widget build(BuildContext context) {
    final task = context.read<TaskDetailProv>();
    Future<void> launchTikTokInAppStore() async {
      const appStoreUrl =
          'https://apps.apple.com/us/app/tiktok/id835599320'; // iOS
      const playStoreUrl =
          'https://play.google.com/store/apps/details?id=com.zhiliaoapp.musically'; // Android

      final url = Theme.of(context).platform == TargetPlatform.iOS
          ? appStoreUrl
          : playStoreUrl;

      if (await canLaunchUrl(Uri.parse(url))) {
        await launchUrl(Uri.parse(url));
      } else {
        ScaffoldMessenger.of(context).showSnackBar(
          const SnackBar(content: Text('无法打开应用商店')),
        );
      }
    }

    void launchApp() async {
      final Map<String, String> platformMap = {
        'TIKTOK': 'tiktok://upload',
        'INSTAGRAM': 'instagram://create'
      };
      String url = platformMap[task.taskDtail?.platformStr] ?? '';

      if (await canLaunchUrl(Uri.parse(url))) {
        await launchUrl(
          Uri.parse(url),
          mode: LaunchMode.externalApplication,
        );
      } else {
        // 如果 TikTok 应用未安装，可以跳转到应用商店
        await launchTikTokInAppStore();
      }
    }

    return SizedBox(
      height: 46.h,
      child: Row(
        // mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          SizedBox(
            width: 15.w,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Expanded(
                  child: Container(
                    width: 1,
                    color: step == 1 ? Colors.transparent : Color(0XFF555555),
                  ),
                ),
                if (status.isNotEmpty)
                  SvgPicture.asset(
                    stateIcon,
                    width: 15.w,
                    height: 15.h,
                  ),
                if (status.isEmpty) ...[
                  Container(
                    width: 11.w,
                    height: 11.h,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(11).r,
                      color: Color(0XFF555555),
                    ),
                  )
                ],
                Expanded(
                  child: Container(
                    width: 1,
                    color: step == 4 ? Colors.transparent : Color(0XFF555555),
                  ),
                ),
              ],
            ),
          ),
          SizedBox(width: 5.w),
          Expanded(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                // 第四步单独处理，样式不一样
                if (step != 4) ...[
                  Expanded(
                    child: Text(
                      stepTitle,
                      style: customTextStyle(
                        opacity: isActive ? 1 : 0.5,
                        fontWeight: isActive ? 600 : 400,
                        fontSize: 14,
                      ),
                      maxLines: 2,
                    ),
                  ),
                ],

                // 步骤1 状态
                if (step == 1) ...[
                  GestureDetector(
                    onTap: () => {
                      if (!isExpired)
                        {
                          showModalBottomSheet(
                            context: context,
                            isScrollControlled: true,
                            backgroundColor: Colors.transparent,
                            builder: ((context) {
                              return TaskFlowSheet();
                            }),
                          ),
                        }
                    },
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(
                          status == '1'
                              ? 'Pending'
                              : status == '3'
                                  ? 'Not Approved'
                                  : 'Approved',
                          style: customTextStyle(
                            opacity: isActive ? 1 : 0.5,
                            fontWeight: isActive ? 600 : 400,
                          ),
                        ),
                        SizedBox(width: 10.w),
                        SvgPicture.asset(
                          'assets/icons/icon_arrow.svg',
                          width: 6.w,
                          height: 12.h,
                        )
                      ],
                    ),
                  ),
                ],
                if (step == 2 && status.isNotEmpty && status == '1') ...[
                  SizedBox(
                    width: 60.w,
                    height: 20.h,
                    child: ElevatedButton(
                      style: ElevatedButton.styleFrom(
                          backgroundColor: AppColors.shareBtnColor,
                          disabledBackgroundColor: Colors.red.shade50,
                          padding: EdgeInsets.zero),
                      onPressed: isExpired ? () => {} : launchApp,
                      // onPressed: () => {
                      //   logger.w("platformStr===${task.taskDtail!.platformStr}"),
                      //   if (task.taskDtail != null){
                      //     if (task.taskDtail!.platformStr == "INSTAGRAM")
                      //       {ShareUtils.shareImageToInstagram("")}
                      //     else
                      //       if (task.taskDtail!.platformStr == "YOUTUBE")
                      //         {ShareUtils.shareImageToYoutube("")}
                      //   },
                      // },
                      child: Text('SHARE', style: customTextStyle()),
                    ),
                  )
                ],
                // status 1 待上传 2 上传审核 3 审核通过 4 失败
                if (step == 3 && status.isNotEmpty && status != '3') ...[
                  status == '2'
                      ? GestureDetector(
                          onTap: () => {
                            if (!isExpired)
                              {
                                showModalBottomSheet(
                                  context: context,
                                  isScrollControlled: true,
                                  backgroundColor: Colors.transparent,
                                  builder: ((context) {
                                    return TaskFlowUploadSheet(type: 'reView');
                                  }),
                                )
                              }
                          },
                          child: Row(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Text(
                                'Under Review',
                                style: customTextStyle(
                                  opacity: 0.5,
                                ),
                              ),
                              SizedBox(width: 10.w),
                              SvgPicture.asset(
                                'assets/icons/icon_arrow.svg',
                                width: 6.w,
                                height: 12.h,
                              )
                            ],
                          ),
                        )
                      : SizedBox(
                          width: 60.w,
                          height: 20.h,
                          child: ElevatedButton(
                            style: ElevatedButton.styleFrom(
                                backgroundColor: AppColors.shareBtnColor,
                                disabledBackgroundColor: Colors.red.shade50,
                                padding: EdgeInsets.zero),
                            onPressed: () {
                              if (!isExpired) {
                                showModalBottomSheet(
                                  context: context,
                                  isScrollControlled: true,
                                  backgroundColor: Colors.transparent,
                                  builder: ((context) {
                                    return TaskFlowUploadSheet();
                                  }),
                                );
                              }
                            },
                            child: Text(retry ? 'RETRY' : 'UPLOAD',
                                style: customTextStyle()),
                          ),
                        )
                ],
                // 1 奖励审核 // 3 失败
                if (step == 4) ...[
                  // 失败需要单读处理
                  if (status == '3') ...[
                    Expanded(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text(
                                'Reward Rejected',
                                style: customTextStyle(
                                  fontSize: 14,
                                ),
                              ),
                              Text(
                                'Please contact customer service',
                                style: customTextStyle(
                                  overflow: TextOverflow.ellipsis,
                                  height: 1.5,
                                  opacity: 0.5,
                                ),
                                maxLines: 1,
                              ),
                            ],
                          ),
                          if (status == '3')
                            SvgPicture.asset(
                              'assets/icons/icon_arrow.svg',
                              width: 6.w,
                              height: 12.h,
                            )
                        ],
                      ),
                    )
                  ],
                  if (status != '3') ...[
                    Text(
                      stepTitle,
                      style: customTextStyle(
                        opacity: isActive ? 1 : 0.5,
                        fontWeight: isActive ? 600 : 400,
                        fontSize: 14,
                      ),
                    ),
                    SizedBox(width: 5.w),
                    Expanded(
                      child: Text(
                        statusStr,
                        style: customTextStyle(
                          overflow: TextOverflow.ellipsis,
                          height: 1.5,
                          opacity: status == '3' ? 0.5 : 1,
                        ),
                        maxLines: 1,
                      ),
                    )
                  ]
                ],
              ],
            ),
          ),
        ],
      ),
    );
  }
}
